using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

namespace Sedge.UI.Component
{
	public enum BevelStyle
	{
		Lowered, Raised, Flat
	}

	public class Bevel : Control
	{
		private Container _components;

		private const Border3DSide DefaultShape = Border3DSide.Bottom;
		private const BevelStyle DefaultStyle = BevelStyle.Lowered;

		/// <summary>
		/// Initializes a new instance of the <see cref="Bevel"/> class.
		/// </summary>
		public Bevel()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			SetStyle(ControlStyles.ResizeRedraw, true);
			SetStyle(ControlStyles.DoubleBuffer, true);

			_style = DefaultStyle;
			_shape = DefaultShape;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (_components != null)
					_components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			_components = new System.ComponentModel.Container();
		}
		#endregion

		/// <summary>Paints the rule.</summary>
		protected override void OnPaint(PaintEventArgs e)
		{
			// Create a local version of the graphics object for the Bevel.
			Graphics g = e.Graphics;
			Rectangle r = ClientRectangle;

			if (Style != BevelStyle.Flat)
			{
				Border3DStyle style = Border3DStyle.SunkenOuter;
				if (Style == BevelStyle.Raised)
					style = Border3DStyle.RaisedInner;

				// Draw the Bevel.
				switch (Shape)
				{
					case Border3DSide.All:
						ControlPaint.DrawBorder3D(g, r.Left, r.Top, r.Width, r.Height, style);
						break;
					case Border3DSide.Left:
						ControlPaint.DrawBorder3D(g, r.Left, r.Top, 2, r.Height, style);
						break;
					case Border3DSide.Top:
						ControlPaint.DrawBorder3D(g, r.Left, r.Top, r.Width, 2, style);
						break;
					case Border3DSide.Bottom:
						ControlPaint.DrawBorder3D(g, r.Left, r.Bottom - 2, r.Width, 2, style);
						break;
					case Border3DSide.Middle:
						break;
					case Border3DSide.Right:
						ControlPaint.DrawBorder3D(g, r.Right - 2, r.Top, 2, r.Height, style);
						break;
					default:
						Debug.Assert(false);
						break;
				}
			}

			// Calling the base class OnPaint
			base.OnPaint(e);
		}

		private Border3DSide _shape;
		/// <summary>
		/// Gets or sets the shape of the bevel.
		/// </summary>
		[DefaultValue(DefaultShape)]
		public Border3DSide Shape
		{
			get
			{
				return _shape;
			}
			set
			{
				_shape = value;
				Invalidate();
			}
		}

		private BevelStyle _style;
		/// <summary>
		/// Gets or sets the style of the bevel.
		/// </summary>
		[DefaultValue(DefaultStyle)]
		public BevelStyle Style
		{
			get
			{
				return _style;
			}
			set
			{
				_style = value;
				Invalidate();
			}
		}
	
	}
}